package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;

/**
 * 
 * @author Andrea Scripa
 * 
 */
// Wanted to implement functionality that gave user the choice to save either
// their active Pixmap or their active History. But this would have required
// having tabs working first.
public class Save {
	ResourceBundle myViewLabels = ResourceBundle
			.getBundle("resources.englishView");
	private JFrame optionWindow;
	private JButton button;

	public void execute() {
		ArrayList<String> historyToSave = HistoryArea.getActiveHistory();
		String saveMessage = myViewLabels.getString("SaveMessage");
		optionWindow = new JFrame(myViewLabels.getString("SaveWindow"));
		
		JPanel messagePanel = new JPanel(new BorderLayout());
		JTextArea messageArea = new JTextArea();
		messageArea.setText(saveMessage);
		messageArea.setEditable(false);
		messageArea.setLineWrap(true);
		messageArea.setWrapStyleWord(true);
		messagePanel.add(messageArea, BorderLayout.CENTER);
		messagePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		optionWindow.add(messagePanel, BorderLayout.NORTH);
		
		JPanel buttonPanel = new JPanel(new BorderLayout());
		buttonPanel.add(makeButton(myViewLabels.getString("SaveCanvasButton")),
				BorderLayout.WEST);
		buttonPanel.add(makeButton(myViewLabels.getString("SaveHistoryButton")),
				BorderLayout.EAST);
		buttonPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		optionWindow.add(buttonPanel, BorderLayout.SOUTH);

		optionWindow.pack();
		optionWindow.setVisible(true);
	}

	private JButton makeButton(String name) {
		button = new JButton(name);
		button.setActionCommand(name);
		button.setBorder(BorderFactory.createEmptyBorder());
		button.addActionListener((ActionListener) this);
		return button;
	}
	
	private void actionPerformed(ActionEvent e)
	{
		if (myViewLabels.getString("SaveCanvasButton").equals(e.getActionCommand()))
		{
			//get the Canvas
			//save the Canvas
			optionWindow.dispose();
		}
		
		else
		{
			//save historyToSave
			optionWindow.dispose();
		}
	}
}
